
let listeners = [];
let nexts = []
//监听
export function takeChannel(actionType, next) {
    next.actionType = actionType;
    listeners.push(next);
    // 从listeners中将这个next取消掉
    next.cancel = function () {
        //!特别主要过滤不用splice, 会改变原数组
        listeners.filter(item => item !== next);
    }
}

// 触发
export function putChannel(actionType) {
    listeners.forEach(next => {
        // 如果传入的actionType一样，就执行，否则就不执行
        if (next.actionType === actionType) {
            // 取消掉这个监听
            next.cancel();
            next();
        }
    })
}